<script>function doSubmitServerFileSelection() {document.forms['serverFileSelector'].submit();}</script>
<form autocomplete="off" class="fileSelector" id="serverFileSelector" enctype="multipart/form-data" action="<?php print $_SERVER["SCRIPT_NAME"];?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1512000">
<input type="hidden" name="mxL" value="zh">
<?php print $SelectSgfFileLabel;?><br>
<select class="fileSelectorInput" name="sgfServerFile" onchange="doSubmitServerFileSelection()">
	<?php
	// if $firstOption is a non-empty string, display it as first option
	// otherwise if $firstOption is an empty string , display a blank as first option
	// otherwise don't display any first option
	if (isset($firstOption))
	{
		if ($firstOption)
		{
			print "<option>";
			print (isset($firstOption)?$firstOption:"");
			print "</option>\n";
		}
	}
	function makeSgfSelect($dirFullName,$sgfTarget)
	{
		$list=array();
		if (is_dir($dirFullName))
		{
			$dir=new DirectoryIterator($dirFullName);
			foreach($dir as $file)
				if ($file->isFile())
				{
					// $file->getExtension() doesn't work on jeudego.org (2014/11/15)
					$ext=pathinfo($file->getFilename(),PATHINFO_EXTENSION);
					if ($ext=="sgf") array_push($list,$file->getFilename());
				}
		}
		sort($list);
		foreach($list as $item)
		{
			$filename=iconv('GB2312', 'UTF-8', $item);
			echo "<option ".(($sgfTarget==$filename)?"selected":"").">".$filename."</option>\n";
		}
	}
	if (isset($sgfDir)&&isset($sgfTarget)) makeSgfSelect($sgfDir,$sgfTarget);
	?>
</select>
</form>
